//
//  MCPaySelectedLotteryTableViewController.m
//  TLYL
//
//  Created by miaocai on 2017/6/14.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCPaySelectedLotteryTableViewController.h"
#import "MCPaySelectedLotteryTableViewCell.h"
#import "MCPaySelectedLotteryHeaderView.h"
#import "MCPaySelectedLotteryFooterView.h"
#import "MCMineCellModel.h"
#import "MCChaseNumberViewController.h"
#import "MCPaySelectedLotteryModel.h"
#import "MCMMCNewViewController.h"
#import "MCMMCPresentationController.h"
#import "MCMSPopView.h"
#import "MCBetModel.h"
#import "MCMineInfoModel.h"
#import "MCUserMoneyModel.h"
#import "ExceptionView.h"
#import "MCIssueModel.h"
#import "MCMaxbonusModel.h"
#import "MCGameRecordViewController.h"
#import "MCMainNavigationController.h"
#import "UIView+MCParentController.h"
#define ApplicationNavigationBarBackGauge 7 //导航栏图片距屏幕边缘间距
@interface MCPaySelectedLotteryTableViewController ()
<
UITableViewDelegate,
UITableViewDataSource,
UIAlertViewDelegate,
MCPaySelectedLotteryFooterDelegate
>
/**view_header*/
@property(nonatomic, strong)MCPaySelectedLotteryHeaderView *paySelectedLotteryHeaderView;
/**view_footer*/
@property(nonatomic, strong)MCPaySelectedLotteryFooterView *paySelectedLotteryFooterView;
/**tableView*/
@property(nonatomic, strong)UITableView *tableView;
/**Section模型数组*/
@property(nonatomic, strong)NSMutableArray*sectionMarr;
/**dataSourceModel*/
@property(nonatomic, strong)MCPaySLBaseModel*dataSourceModel;

/**apiModel(投注接口)*/
@property(nonatomic, strong)MCBetModel *betModel;

@property(nonatomic, strong)MCUserMoneyModel *userMoneyModel;
@property(nonatomic, strong)MCIssueModel *issueModel;

@property(nonatomic, strong)ExceptionView * exceptionView;

@end

@implementation MCPaySelectedLotteryTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self setProperty];
    
    [self setNav];
    
    [self createUI];

}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.navigationBar.translucent = NO;
    
    [self checkData];
}
-(void)checkData{
//    __weak __typeof__ (self) wself = self;
//    if ([self.baseWFmodel.LotteryID isEqualToString:@"50"]){
//    //秒秒彩不调用倒计时
        [self create_SectionMarr];
        
        _paySelectedLotteryFooterView.dataSource=_dataSourceModel;
        _paySelectedLotteryHeaderView.hidden=YES;

//    }else{
//        if (!_RemainTime||_IssueNumber==nil || [_IssueNumber isEqualToString:@""]) {
//            self.exceptionView = [ExceptionView exceptionViewWithType:ExceptionCodeTypeRequestFailed];
//            ExceptionViewAction *action = [ExceptionViewAction actionWithType:ExceptionCodeTypeRequestFailed handler:^(ExceptionViewAction *action) {
//                [wself.exceptionView dismiss];
//                wself.exceptionView = nil;
//
//                [wself getData];
//                
//            }];
//            [self.exceptionView addAction:action];
//            [self.exceptionView showInView:wself.view];
//            
//        }else{
//            
//            [self loadData];
//            [self getData];
//            
//        }
//    }
//    
//    //刷新余额
//    MCUserMoneyModel * userMoneyModel=[MCUserMoneyModel sharedMCUserMoneyModel];
//    [userMoneyModel refreashDataAndShow];
//    self.userMoneyModel=userMoneyModel;
//    userMoneyModel.callBackSuccessBlock = ^(id manager) {
//        
//        wself.userMoneyModel.FreezeMoney=manager[@"FreezeMoney"];
//        wself.userMoneyModel.LotteryMoney=manager[@"LotteryMoney"];
//        
//        wself.dataSourceModel.balance=manager[@"LotteryMoney"];
//        wself.paySelectedLotteryFooterView.dataSource=wself.dataSourceModel;
//    };
    
}

-(void)getData{
    MCIssueModel *issueModel = [[MCIssueModel alloc] init];
    issueModel.lotteryNumber = [_dataSourceModel.LotteryID intValue];
    [issueModel refreashDataAndShow];
    self.issueModel = issueModel;
    __weak typeof(self) weakSelf = self;
    issueModel.callBackSuccessBlock = ^(id manager) {
        MCIssueModel *model = [MCIssueModel mj_objectWithKeyValues:manager];
        weakSelf.RemainTime= model.RemainTime;
        weakSelf.IssueNumber=model.IssueNumber;
        [weakSelf loadData];
    };
    issueModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {

        [weakSelf checkData];
    };


}



#pragma mark==================setProperty======================
-(void)setProperty{
    self.view.backgroundColor=RGB(239, 246, 252);
    
    
    _sectionMarr= [[NSMutableArray alloc]init];
    if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.automaticallyAdjustsScrollViewInsets = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        self.navigationController.navigationBar.clipsToBounds = NO;
    }
    MCPaySLBaseModel * model=[MCPaySLBaseModel sharedMCPaySLBaseModel];
    _dataSourceModel=model;
    
    self.title=_dataSourceModel.czName;
}
#pragma mark ====================设置导航栏========================
-(void)setNav{
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, MC_REALVALUE(28), MC_REALVALUE(28));
    [rightBtn addTarget:self action:@selector(emptyShoppingCart) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setImage:[UIImage imageNamed:@"Navigation_delete_selected"] forState:UIControlStateNormal];
    UIBarButtonItem *rewardItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceItem.width = -ApplicationNavigationBarBackGauge;
    self.navigationItem.rightBarButtonItems = @[spaceItem,rewardItem];
    
}

#pragma mark-清空购彩篮
-(void)emptyShoppingCart{
    [_sectionMarr removeAllObjects];
    [_dataSourceModel removeDataSource];
    [_tableView reloadData];
    _paySelectedLotteryFooterView.dataSource=_dataSourceModel;
}

#pragma mark==================createUI======================
-(void)createUI{
    
    _paySelectedLotteryHeaderView=[[MCPaySelectedLotteryHeaderView alloc]init];
    __weak typeof(self) weakSelf = self;
    _paySelectedLotteryHeaderView.timeISZeroBlock = ^{
        [weakSelf getData];
    };
    [self.view addSubview:_paySelectedLotteryHeaderView];
    _paySelectedLotteryHeaderView.frame=CGRectMake(0, 0, G_SCREENWIDTH, [MCPaySelectedLotteryHeaderView computeHeight:nil]);
    
    _paySelectedLotteryFooterView=[[MCPaySelectedLotteryFooterView alloc]init];
    [self.view addSubview:_paySelectedLotteryFooterView];
    _paySelectedLotteryFooterView.delegate=self;
    CZType type=[_dataSourceModel.czName  rangeOfString:@"秒秒彩"].location !=NSNotFound?MCMMC:MCOther;
    int Height_footer=[MCPaySelectedLotteryFooterView computeHeight:type];
    _paySelectedLotteryFooterView.frame=CGRectMake(0, G_SCREENHEIGHT-Height_footer-64, G_SCREENHEIGHT, Height_footer);
    [_paySelectedLotteryFooterView relayOutWithType:type];
    _paySelectedLotteryFooterView.block=^(NSInteger t){
#pragma mark-点击追号
        if (t==1001) {
            if (_dataSourceModel.dataSource.count<1) {
                [SVProgressHUD showErrorWithStatus:@"至少选择一注！"];
                return ;
            }
            MCChaseNumberViewController *chsaseNumberController = [[MCChaseNumberViewController alloc] init];
            chsaseNumberController.dataSourceModel = weakSelf.dataSourceModel;
            chsaseNumberController.RemainTime=weakSelf.paySelectedLotteryHeaderView.dataSource;
            chsaseNumberController.IssueNumber=weakSelf.IssueNumber;
            chsaseNumberController.boModelArray=weakSelf.boModelArray;
            chsaseNumberController.baseWFmodel=weakSelf.baseWFmodel;
            chsaseNumberController.yuEHadChangedBlock = ^(NSString *yue) {
                [weakSelf refreashUserMoney];
            };
            [weakSelf.navigationController pushViewController:chsaseNumberController animated:YES];
            
#pragma mark-点击付款
        }else if(t==1002){
            if ([weakSelf.dataSourceModel.payMoney floatValue]<0.001) {
                [SVProgressHUD showErrorWithStatus:@"付款金额必须大于0！"];
                return;
            }
            
            if ([weakSelf.dataSourceModel.payMoney floatValue]>[self.dataSourceModel.balance floatValue]) {
                [SVProgressHUD showInfoWithStatus:@"余额不足!"];
                return;
            }
            int mode = (int)[[NSUserDefaults standardUserDefaults] objectForKey:MerchantMode];
            NSString *maxstr = @"";
            if ((mode & 128) == 128) {//单期功能
                for (MCMaxbonusModel *model in weakSelf.boModelArray) {
                    if ([model.Sign isEqualToString:@"1"]) {
                        //                            continue;
                    }
                    
                    NSString *lotName =  [MCLotteryID getLotteryCategoriesTypeNameByID:weakSelf.baseWFmodel.LotteryID];
                    if ([lotName isEqualToString:@"ssc"] &&[model.SingleStageCode isEqualToString:@"1001"]) {
                        maxstr = model.MaxAmt;
                    }
                    else if ([lotName isEqualToString:@"esf"] &&[model.SingleStageCode isEqualToString:@"2001"]) {
                        maxstr = model.MaxAmt;
                    }
                    else if ([lotName isEqualToString:@"sd"] &&[model.SingleStageCode isEqualToString:@"3001"]) {
                        maxstr = model.MaxAmt;
                    }
                    else if ([lotName isEqualToString:@"pls"] &&[model.SingleStageCode isEqualToString:@"4001"]) {
                        maxstr = model.MaxAmt;
                    }
                    else if ([lotName isEqualToString:@"plw"] &&[model.SingleStageCode isEqualToString:@"5001"]) {
                        maxstr = model.MaxAmt;
                    }
                    else if ([lotName isEqualToString:@"ssl"] &&[model.SingleStageCode isEqualToString:@"6001"]) {
                        maxstr = model.MaxAmt;
                    }
                    else if ([lotName isEqualToString:@"kl8"] &&[model.SingleStageCode isEqualToString:@"7001"]) {
                        maxstr = model.MaxAmt;
                    }
                    else if ([lotName isEqualToString:@"pks"] &&[model.SingleStageCode isEqualToString:@"8001"]) {
                        maxstr = model.MaxAmt;
                    }
                    else if ([lotName isEqualToString:@"k3"] &&[model.SingleStageCode isEqualToString:@"9001"]) {
                        maxstr = model.MaxAmt;
                    }else{
                        continue ;
                    }
                    
                    
                }
            }
            NSString * tip;
            if (maxstr.length>1) {
                 tip =[NSString stringWithFormat:@"该彩种单期最高奖金为%@元\n您共投%@注，共%@元，请确认",GetRealSNum(maxstr ),_dataSourceModel.stakeNumber,GetRealSNum(weakSelf.dataSourceModel.payMoney)];
            }else{
                 tip=[NSString stringWithFormat:@"您共投%@注，共%@元，请确认",_dataSourceModel.stakeNumber,GetRealSNum(weakSelf.dataSourceModel.payMoney)];
            }
            
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:tip preferredStyle:UIAlertControllerStyleAlert];
            // 添加按钮
            __weak typeof(alert) weakAlert = alert;
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

                NSLog(@"点击了确定按钮--%@-%@", [weakAlert.textFields.firstObject text], [weakAlert.textFields.lastObject text]);
                
                [weakSelf lottery_bet];
                
                
            }]];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"关闭" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                NSLog(@"点击了取消按钮");
            }]];
            [weakSelf presentViewController:alert animated:YES completion:nil];
        }
    };
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_paySelectedLotteryHeaderView.mas_bottom).offset(0);
        make.left.and.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view.mas_bottom).offset(-[MCPaySelectedLotteryFooterView computeHeight:type]);
    }];

    UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closePopView:)];
    singleTapGesture.numberOfTapsRequired = 1;
    singleTapGesture.cancelsTouchesInView = NO;
    [_tableView addGestureRecognizer:singleTapGesture];
   
}

#pragma mark-投注
-(void)lottery_bet{
    NSMutableArray * betMarr=[[NSMutableArray alloc]init];
    __weak __typeof__ (self) wself = self;
    for (MCPaySelectedCellModel * model in _dataSourceModel.dataSource) {
        NSDictionary * betDic = @{
                                  @"BetContent":model.tz_haoMa,//投注内容
                                  @"BetCount":model.stakeNumber,//投注注数
                                  @"PlayCode":model.PlayCode,//玩法编码
                                  @"IssueNumber":self.IssueNumber,//投注期号
                                  @"BetRebate":model.BetRebate,//投注返点
                                  @"BetMoney":model.payMoney,//投注金额
                                  @"BetMultiple":model.multiple,//投注倍数
                                  @"BetMode":model.BetMode//玩法模式
                                  };
        [betMarr addObject:betDic];
    }
    NSDictionary * dic =@{
                          @"UserBetInfo":@{
//                                  @"IssueNumber":_IssueNumber,//投注期号
                                  @"LotteryCode":_dataSourceModel.LotteryID,//彩种编码
                                  @"Bet":betMarr
                                          }
                          };
    
    MCBetModel *betModel = [[MCBetModel alloc] initWithDic:dic];
    self.betModel=betModel;
    [betModel refreashDataAndShow];
    betModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSString *errorCode) {
    };
    betModel.callBackSuccessBlock = ^(id manager) {
        //投注成功
        [wself betSuccessToDo];
    };
}

#pragma mark-投注成功后要做的事情
-(void)betSuccessToDo{
    //1.清空购彩蓝
    _dataSourceModel.balance=[NSString stringWithFormat:@"%@",GetRealFloatNum([_dataSourceModel.balance doubleValue]-[_dataSourceModel.payMoney doubleValue])];
    [self emptyShoppingCart];
  
    //2.刷新余额
    [self refreashUserMoney];
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"投注成功" delegate:self cancelButtonTitle:@"查看记录" otherButtonTitles:@"继续投注", nil];
    alert.alertViewStyle = UIAlertViewStyleDefault;
    alert.delegate=self;
    alert.alertViewStyle = UIAlertViewStyleDefault;
    [alert show];
    
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    //查看记录
    if (buttonIndex==0) {
        
        //获得视图控制器堆栈数组
        NSArray *currentControllers = self.navigationController.viewControllers;
        //基于堆栈数组实例化新的数组
        NSMutableArray *newControllers = [NSMutableArray arrayWithArray:currentControllers];
        int count = (int)newControllers.count;
        
        [newControllers removeObjectAtIndex:(count-1)];
        
        MCGameRecordViewController * vc = [[MCGameRecordViewController alloc]init];

        UIViewController * pVC=[newControllers lastObject];
    
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

        
        [UIView animateWithDuration:0.001 animations:^{
            //为堆栈重新赋值
            [self.navigationController setViewControllers:newControllers animated:NO];
            
        } completion:^(BOOL finished) {
            
            [pVC.navigationController pushViewController:vc animated:YES];
            
        }];

        
    //继续投注
    }else if (buttonIndex==1){
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }
    
}


#pragma mark - gesture actions
- (void)closePopView:(UITapGestureRecognizer *)recognizer {
    
    MCMSPopView *popView = [MCMSPopView alertInstance];
    
    [popView hideModelWindow];
    
}

#pragma mark==================loadData======================
-(void)loadData{
    
    

    [self create_SectionMarr];
    
    _paySelectedLotteryFooterView.dataSource=_dataSourceModel;
    _paySelectedLotteryHeaderView.IssueNumber=_IssueNumber;
    _paySelectedLotteryHeaderView.dataSource=_RemainTime;
    _paySelectedLotteryHeaderView.hidden=NO;
    
    
}

-(void)create_SectionMarr{
    [_sectionMarr removeAllObjects];
    NSMutableArray * marr_Model=[[NSMutableArray alloc]init];
    for(int i=0 ;i<_dataSourceModel.dataSource.count; i++){
        CellModel* model =[[CellModel alloc]init];
        model.reuseIdentifier = NSStringFromClass([MCPaySelectedLotteryTableViewCell class]);
        model.className=NSStringFromClass([MCPaySelectedLotteryTableViewCell class]);
        model.height = [MCPaySelectedLotteryTableViewCell computeHeight:nil];
        model.selectionStyle=UITableViewCellSelectionStyleNone;
        model.accessoryType=UITableViewCellAccessoryNone;
        /*
         * 传递参数
         */
        model.userInfo = _dataSourceModel.dataSource[i];
        [marr_Model addObject:model];
    }
    SectionModel *model0=[SectionModel sectionModelWithTitle:@"" cells:marr_Model];
    model0.headerhHeight=0.0001;
    model0.footerHeight=0.0001;
    [_sectionMarr addObject:model0];
    [_tableView reloadData];
}
#pragma mark tableView 代理相关
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _sectionMarr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    SectionModel *sm = _sectionMarr[section];
    return sm.cells.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    SectionModel *sm = _sectionMarr[section];
    return sm.headerhHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    SectionModel *sm = _sectionMarr[section];
    return sm.footerHeight;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    SectionModel *sm = _sectionMarr[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    
    return cm.height;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SectionModel *sm = _sectionMarr[indexPath.section];
    CellModel *cm = sm.cells[indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cm.reuseIdentifier];
    if (!cell) {
        cell = [[NSClassFromString(cm.className) alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cm.reuseIdentifier];
    }
    cell.selectionStyle = cm.selectionStyle;
    
    if ([cm.className isEqualToString:NSStringFromClass([MCPaySelectedLotteryTableViewCell class])]) {
        
        MCPaySelectedLotteryTableViewCell *ex_cell=(MCPaySelectedLotteryTableViewCell *)cell;
        ex_cell.dataSource=cm.userInfo;
        __block MCPaySelectedLotteryTableViewController *weakSelf = self;
        ex_cell.block=^(){
            
            
            MCPaySelectedCellModel * dModel= weakSelf.dataSourceModel.dataSource[indexPath.row];
            [weakSelf.dataSourceModel  deleteDataSourceWithModel:dModel];
            weakSelf.dataSourceModel=[MCPaySLBaseModel sharedMCPaySLBaseModel];
            [weakSelf create_SectionMarr];
            [weakSelf.tableView reloadData];
            weakSelf.paySelectedLotteryFooterView.dataSource=weakSelf.dataSourceModel;
        };
    }
    return cell;
}


#pragma mark-MCPaySelectedLotteryFooterDelegate-立即开奖
-(void)goToRunLotteryImmediately{

    if ([self.dataSourceModel.payMoney floatValue]*_paySelectedLotteryFooterView.lianKaiCount<0.0001) {
        [SVProgressHUD showInfoWithStatus:@"付款金额必须大于0元！"];
        return;
    }
    
    MCMSPopView *popView = [MCMSPopView alertInstance];
    [popView hideModelWindow];
    NSMutableArray * betMarr=[[NSMutableArray alloc]init];
    
    NSString * tip=[NSString stringWithFormat:@"您选择了%d注,共%@元,请确认",[self.dataSourceModel.stakeNumber intValue],GetRealFloatNum([self.dataSourceModel.payMoney floatValue]*_paySelectedLotteryFooterView.lianKaiCount)];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:tip preferredStyle:UIAlertControllerStyleAlert];
    // 添加按钮
    __weak typeof(MCPaySelectedLotteryTableViewController *) weakSelf = self;
    NSString * BetRebate=@"";
    
    for (MCPaySelectedCellModel * model in _dataSourceModel.dataSource) {
        if (model.BetRebate) {
            BetRebate=model.BetRebate;
        }
        NSDictionary * betDic = @{
                                  @"BetContent":model.tz_haoMa,//投注内容
                                  @"BetCount":model.stakeNumber,//投注注数
                                  @"PlayCode":model.PlayCode,//玩法编码
//                                  @"IssueNumber":model.IssueNumber,//投注期号
                                  @"BetRebate":BetRebate,//投注返点
                                  @"BetMoney":model.payMoney,//投注金额
                                  @"BetMultiple":model.multiple,//投注倍数
                                  @"BetMode":model.BetMode//玩法模式
                                  };
        
        [betMarr addObject:betDic];
        
    }
    
    NSDictionary * dic =@{
                          @"UserBetInfo":@{
                                  @"LotteryCode":_dataSourceModel.LotteryID,//彩种编码
                                  @"Bet":betMarr
                                  }
                          
                          };
    
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        MCMMCNewViewController *VC = [[MCMMCNewViewController alloc]init];
        VC.dic=dic;
        VC.lianKaiCount=_paySelectedLotteryFooterView.lianKaiCount;
        MCMMCPresentationController *PC = [[MCMMCPresentationController alloc] initWithPresentedViewController:VC presentingViewController:self];
        VC.transitioningDelegate = PC;
        [weakSelf presentViewController:VC animated:YES completion:NULL];
        

        
        
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"点击了取消按钮");
    }]];
    [self presentViewController:alert animated:YES completion:nil];
    
    
    
   
}

//刷新账户
-(void)refreashUserMoney{
    MCUserMoneyModel * userMoneyModel=[MCUserMoneyModel sharedMCUserMoneyModel];
    [userMoneyModel refreashDataAndShow];
    self.userMoneyModel=userMoneyModel;
    userMoneyModel.callBackSuccessBlock = ^(id manager) {
        
        self.userMoneyModel.FreezeMoney=manager[@"FreezeMoney"];
        self.userMoneyModel.LotteryMoney=manager[@"LotteryMoney"];
        
        self.dataSourceModel.balance=manager[@"LotteryMoney"];
        
    };
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    MCMSPopView *popView = [MCMSPopView alertInstance];
    [popView.dataArray removeAllObjects];
    popView.dataArray=nil;
    [popView hideModelWindow];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)alertSucPopViewControllerAnimated{
    [self.navigationController popViewControllerAnimated:NO];
}
@end

















